<template>
  <div class="box1">
    <el-container>
      <el-header>
        <h4>欢迎来到德莱联盟</h4>
        <el-menu
          class="el-menu-demo"
          mode="horizontal"
          background-color="#545c64"
          text-color="#fff"
          active-text-color="#ffd04b"
        >
          <el-menu-item
            :index="key"
            v-for="(item, key) in navlist"
            :key="key"
            @click="select(key)"
            >{{ item.name }}</el-menu-item
          >
          <el-submenu index="2">
            <template slot="title"
              >{{ $store.state.login[0].username }}工作台</template
            >
            <el-menu-item index="2-1">修改</el-menu-item>
            <el-menu-item index="2-2" @click="out">退出</el-menu-item>
          </el-submenu>
        </el-menu>
      </el-header>
      <el-container class="box2">
        <el-aside :width="flag ? '66px' : '200px'">
          <p @click="dj">|||</p>
          <el-menu
            default-active="2"
            class="el-menu-vertical-demo"
            background-color="#545c64"
            text-color="#fff"
            active-text-color="#ffd04b"
            :unique-opened="true"
            :collapse="flag"
            router
          >
            <el-menu-item
              :index="item.url"
              v-for="(item, key) in erji"
              :key="key"
            >
              <i class="el-icon-menu"></i>
              <span slot="title">{{ item.name }}</span>
            </el-menu-item>
          </el-menu>
        </el-aside>
        <el-main>
          <!-- 面包屑 -->
          <bread></bread>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
//导入面包屑
import bread from "@/admin/bread/bread";
import nav from "@/Utils/list"; //导入导航栏数据
export default {
  components: { bread },
  data() {
    return {
      flag: false,
      //导航栏
      navlist: [],
      //侧边栏
      erji: [],
    };
  },
  methods: {
    dj() {
      this.flag = !this.flag;
    },
    //获取侧边栏数据
    select(key) {
      // alert(key)
      this.erji = this.navlist[key].children;
      console.log(this.erji);
    },
    //退出
    out() {
      this.$http
        .post("/admin/logout")
        .then((res) => {
          console.log(res);
          if (res.data.msg == "ok") {
            this.$store.commit("log");
            this.$router.push("/login");
          }
        })
        .catch((err) => {
          console.log(err.response);
        });
    },
  },
  //导航栏数据
  created() {
    this.navlist = nav;
  },
};
</script>

<style lang='scss'>
.box1 {
  width: 100%;
  height: 100%;
  display: flex;
  .box2 {
    flex: 1;
  }
}
.el-header {
  background-color: #545c64;
  color: #333;
  //   line-height: 60px;
  display: flex;
  justify-content: space-between;
  h4 {
    line-height: 60px;
  }
}

.el-aside {
  background-color: #545c64;
  color: #333;
  text-align: center;
  p {
    background: #dddddd;
    width: 100%;
    height: 30px;
    line-height: 30px;
  }
}

.el-main {
  background-color: #e9eef3;
  color: #333;
}
.el-menu {
  border-right: none;
}
</style>